package com.example.testvolication.config;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * <p>参数校验注解对应: 配置快速失败模式</p>
 * @author zhangs
 * @date 2022/5/18 10:52
 */
@Configuration
public class ValidConfiguration {

    /**
     * <p>
     *     支持快速失败
     * </p>
     * @return
     */
    @Bean
    public Validator validator(){
        ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
                .configure()
                // 支持快速失败
                .failFast(true)
                .buildValidatorFactory();
        return validatorFactory.getValidator();
    }
}
